home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 July / CHIP 2006-07.2.iso / program / web_gelistirme / easyphp1-7_setup.exe / {app} / phpmyadmin / libraries / bookmark.lib.php < prev    next >
Encoding:
PHP Script  |  2003-09-07  |  5.6 KB  |  172 lines

  1. <?php
  2. /* $Id: bookmark.lib.php,v 1.11 2003/03/12 20:20:32 garvinhicking Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * Set of functions used with the bookmark feature
  7.  */
  8.  
  9.  
  10.  
  11. if (!defined('PMA_BOOKMARK_LIB_INCLUDED')) {
  12.     define('PMA_BOOKMARK_LIB_INCLUDED', 1);
  13.  
  14.     /**
  15.      * Defines the bookmark parameters for the current user
  16.      *
  17.      * @return  array    the bookmark parameters for the current user
  18.      *
  19.      * @global  integer  the id of the current server
  20.      *
  21.      * @access  public
  22.      */
  23.     function PMA_getBookmarksParam()
  24.     {
  25.         global $server;
  26.  
  27.         $cfgBookmark = '';
  28.  
  29.         // No server selected -> no bookmark table
  30.         if ($server == 0) {
  31.             return '';
  32.         }
  33.  
  34.         $cfgBookmark['user']  = $GLOBALS['cfg']['Server']['user'];
  35.         $cfgBookmark['db']    = $GLOBALS['cfg']['Server']['pmadb'];
  36.         $cfgBookmark['table'] = $GLOBALS['cfg']['Server']['bookmarktable'];
  37.  
  38.         return $cfgBookmark;
  39.     } // end of the 'PMA_getBookmarksParam()' function
  40.  
  41.  
  42.     /**
  43.      * Gets the list of bookmarks defined for the current database
  44.      *
  45.      * @param   string   the current database name
  46.      * @param   array    the bookmark parameters for the current user
  47.      *
  48.      * @return  mixed    the bookmarks list if defined, false else
  49.      *
  50.      * @access  public
  51.      */
  52.     function PMA_listBookmarks($db, $cfgBookmark)
  53.     {
  54.         $query  = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
  55.                 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
  56.                 . ' AND user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'';
  57.         if (isset($GLOBALS['dbh'])) {
  58.             $result = PMA_mysql_query($query, $GLOBALS['dbh']);
  59.         } else {
  60.             $result = PMA_mysql_query($query);
  61.         }
  62.  
  63.         // There is some bookmarks -> store them
  64.         if ($result > 0 && mysql_num_rows($result) > 0) {
  65.             $flag = 1;
  66.             while ($row = PMA_mysql_fetch_row($result)) {
  67.                 $bookmark_list[$flag . ' - ' . $row[0]] = $row[1];
  68.                 $flag++;
  69.             } // end while
  70.             return $bookmark_list;
  71.         }
  72.         // No bookmarks for the current database
  73.         else {
  74.             return FALSE;
  75.         }
  76.     } // end of the 'PMA_listBookmarks()' function
  77.  
  78.  
  79.     /**
  80.      * Gets the sql command from a bookmark
  81.      *
  82.      * @param   string   the current database name
  83.      * @param   array    the bookmark parameters for the current user
  84.      * @param   mixed    the id of the bookmark to get
  85.      * @param   string   which field to look up the $id
  86.      *
  87.      * @return  string   the sql query
  88.      *
  89.      * @access  public
  90.      */
  91.     function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id')
  92.     {
  93.         $query          = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
  94.                         . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
  95.                         . ' AND user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
  96.                         . ' AND ' . PMA_backquote($id_field) . ' = ' . $id;
  97.         if (isset($GLOBALS['dbh'])) {
  98.             $result = PMA_mysql_query($query, $GLOBALS['dbh']);
  99.         } else {
  100.             $result = PMA_mysql_query($query);
  101.         }
  102.         $bookmark_query = @PMA_mysql_result($result, 0, 'query') OR FALSE;
  103.  
  104.         return $bookmark_query;
  105.     } // end of the 'PMA_queryBookmarks()' function
  106.  
  107.  
  108.     /**
  109.      * Adds a bookmark
  110.      *
  111.      * @param   array    the properties of the bookmark to add
  112.      * @param   array    the bookmark parameters for the current user
  113.      *
  114.      * @return  boolean  whether the INSERT succeeds or not
  115.      *
  116.      * @access  public
  117.      */
  118.     function PMA_addBookmarks($fields, $cfgBookmark)
  119.     {
  120.         $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
  121.                . ' (id, dbase, user, query, label) VALUES (\'\', \'' . PMA_sqlAddslashes($fields['dbase']) . '\', \'' . PMA_sqlAddslashes($fields['user']) . '\', \'' . PMA_sqlAddslashes(urldecode($fields['query'])) . '\', \'' . PMA_sqlAddslashes($fields['label']) . '\')';
  122.         if (isset($GLOBALS['dbh'])) {
  123.             $result   = PMA_mysql_query($query, $GLOBALS['dbh']);
  124.             if (PMA_mysql_error($GLOBALS['dbh'])) {
  125.                $error = PMA_mysql_error($GLOBALS['dbh']);
  126.                include('./header.inc.php');
  127.                PMA_mysqlDie($error);
  128.             }
  129.         } else {
  130.             $result   = PMA_mysql_query($query);
  131.             if (PMA_mysql_error()) {
  132.                $error = PMA_mysql_error();
  133.                include('./header.inc.php');
  134.                PMA_mysqlDie($error);
  135.             }
  136.         }
  137.  
  138.         return TRUE;
  139.     } // end of the 'PMA_addBookmarks()' function
  140.  
  141.  
  142.     /**
  143.      * Deletes a bookmark
  144.      *
  145.      * @param   string   the current database name
  146.      * @param   array    the bookmark parameters for the current user
  147.      * @param   integer  the id of the bookmark to get
  148.      *
  149.      * @access  public
  150.      */
  151.     function PMA_deleteBookmarks($db, $cfgBookmark, $id)
  152.     {
  153.         $query  = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
  154.                 . ' WHERE user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
  155.                 . ' AND id = ' . $id;
  156.         if (isset($GLOBALS['dbh'])) {
  157.             $result = PMA_mysql_query($query, $GLOBALS['dbh']);
  158.         } else {
  159.             $result = PMA_mysql_query($query);
  160.         }
  161.     } // end of the 'PMA_deleteBookmarks()' function
  162.  
  163.  
  164.     /**
  165.      * Bookmark Support
  166.      */
  167.     $cfg['Bookmark'] = PMA_getBookmarksParam();
  168.  
  169.  
  170. } // $__PMA_BOOKMARK_LIB__
  171. ?>
  172.